package com.lanou.elh.sysmanage.system_management.web.controller;

import com.lanou.elh.sysmanage.authority_management.common.Result;
import com.lanou.elh.sysmanage.authority_management.common.ResultUtil;
import com.lanou.elh.sysmanage.system_management.entity.TbExpress;
import com.lanou.elh.sysmanage.system_management.service.ExpressService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ExpressController {
    @Autowired
    private ExpressService expressService;

    @GetMapping("/user/selectAllExpress")
    @ApiOperation(value = "查询所有快递列表")
    public Result<List<TbExpress>> selectAllExpress() {
        List<TbExpress> tbExpresses = expressService.selectExpress();
        return new ResultUtil<List<TbExpress>>().setData(tbExpresses);

    }

    @PostMapping("/admin/deleteByid")
    @ApiOperation(value = "通过id删除单个快递信息")
    public Result deleteById(Integer id) {
        expressService.deleteByid(id);
        return new ResultUtil<>().setData(null);
    }

    @PostMapping("/admin/deleteByManyId")
    @ApiOperation(value = "同时删除多个快递信息")
    public Result deleteByManyId(Integer[] id) {
        expressService.deleteByManyId(id);
        return new ResultUtil<>().setData(null);
    }

    @PostMapping("/admin/addExpress")
    @ApiOperation(value = "增加一个快递信息")
    public Result addExpress(TbExpress express) {
        expressService.addExpress(express);
        return new ResultUtil<>().setData(null);
    }

    @PostMapping("/admin/updateExpress")
    @ApiOperation(value = "修改一个快递信息")
    public Result updateExpressById(TbExpress express) {
        expressService.updateExpressById(express);
        return new ResultUtil<>().setData(null);
    }
}
